import axios from '@/util'; 

import type {
  registDto,
  CreateTokenDto,
  qianTailoginResult,
  UserEntity,
} from './typings';



/**
 * 用户注册 POST /api/register
 */
export async function post_api_register (
  data: {
    /** 用户账号 */
    account?: string;
    /** 密码 */
    password?: string;
    /** 用户名 */
    username?: string;
    /** 邮箱 */
    email?: string;
  },
  options?: Record<string, any>,
): Promise<registDto> {
  return axios({
    method: 'POST',
    url: `/api/register`,
    data: {
      ...data,
    },
    ...(options || {}),
  })
}

/**
 * 登录 POST /api/login
 */
export async function post_api_login (
  data: {
    /** 账号 */
    email?: string;
    /** 密码 */
    password?: string;
  },
  options?: Record<string, any>,
): Promise<CreateTokenDto> {
  return axios({
    method: 'POST',
    url: `/api/login`,
    data: {
      ...data,
    },
    ...(options || {}),
  })
}

/**
 * 登录 POST /api/qianTailogin
 */
export async function post_api_qiantailogin (
  data: {
    /** 账号 */
    email?: string;
    /** 密码 */
    password?: string;
  },
  options?: Record<string, any>,
): Promise<qianTailoginResult> {
  return axios({
    method: 'POST',
    url: `/api/qianTailogin`,
    data: {
      ...data,
    },
    ...(options || {}),
  })
}

/**
 * 微信登录 POST /api/genWeiXinToken
 */
export async function post_api_genweixintoken (
  data: {
    /** 用户code */
    js_code?: string;
    /** 用户token */
    token?: string;
  },
  options?: Record<string, any>,
): Promise<CreateTokenDto> {
  return axios({
    method: 'POST',
    url: `/api/genWeiXinToken`,
    data: {
      ...data,
    },
    ...(options || {}),
  })
}

/**
 * 微信token获取用户信息 POST /api/wxTokenGetInfo
 */
export async function post_api_wxtokengetinfo (
  data: {
    /** 用户code */
    js_code?: string;
    /** 用户token */
    token?: string;
  },
  options?: Record<string, any>,
): Promise<CreateTokenDto> {
  return axios({
    method: 'POST',
    url: `/api/wxTokenGetInfo`,
    data: {
      ...data,
    },
    ...(options || {}),
  })
}

/**
 * 根据token获取用户信息 GET /api/profile
 */
export async function get_api_profile (
  options?: Record<string, any>,
): Promise<UserEntity> {
  return axios({
    method: 'GET',
    url: `/api/profile`,
    ...(options || {}),
  })
}

/**
 * 刷新token POST /api/update/token
 */
export async function post_api_update_token (
  options?: Record<string, any>,
): Promise<CreateTokenDto> {
  return axios({
    method: 'POST',
    url: `/api/update/token`,
    ...(options || {}),
  })
}
